package com.geek.framework.study.config.microprofile.source;

import java.util.Enumeration;
import java.util.Map;
import java.util.function.Supplier;

public abstract class EnumerationConfigSource extends MapBaseConfigSource {

    protected EnumerationConfigSource(String name, int ordinal) {
        super(name, ordinal);
    }

    @Override
    protected void prepareConfigData(Map<String, String> configData) {
        Enumeration<String> parameterNames = getKeyResolver().get();
        while (parameterNames.hasMoreElements()) {
            String key = parameterNames.nextElement();
            configData.put(key, getValueResolver(key));
        }
    }

    /**
     * keys
     * @return
     */
    protected abstract Supplier<Enumeration<String>> getKeyResolver();

    /**
     * value
     * @param key
     * @return
     */
    protected abstract String getValueResolver(String key);

}
